<?php

class OptionsController extends BaseAdminController
{

  protected $Form;

  protected function initialize()
  {
    parent::initialize();

    $this->Form = new Form();
    $this->Form->title = 'Options';
  }

  protected function indexAction()
  {
    $this->Form->addElement(new FormElement_Text('site_name', 'Site name'), Form::ACTION_OPTIONS);
    $this->Form->addElement(new FormElement_Text('site_tagline', 'Site tag line'), Form::ACTION_OPTIONS);

    return $this->showForm('General');
  }

  protected function emailAction()
  {
    $this->Form->addElement(new FormElement_Text('email_from', 'From'), Form::ACTION_OPTIONS);

    return $this->showForm('Email');
  }

  protected function showForm($title)
  {
    $this->Form->getAction(Form::ACTION_OPTIONS)->title = $title;

    try {
      $this->Form->execute(Form::ACTION_OPTIONS);
    }
    catch (ValidationException $e) {
      s::getInstance()->warnings($e->getErrors());
    }

    return $this->Form->render(Form::ACTION_OPTIONS);
  }

}
